<%--
  Created by IntelliJ IDEA.
  User: 123456
  Date: 2023/5/25
  Time: 10:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>Title</title>
        <style>
            * {margin: 0;padding: 0;}

            html {height: 100%;}

            body { height: 100%;}

            .container {
                height: 100%;
                background-color: antiquewhite;
            }

            .big {
                background-image: linear-gradient(to right, #a9c4f2, rgb(173, 173, 173));
                width: 400px;
                height: 550px;
                border-radius: 50px;
                padding: 0 50px;
                position: relative;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
            }

            .header {
                font-size: 60px;
                font-weight: 900;
                text-align: center;
                line-height: 120px;
            }

            .input-item {
                display: block;
                width: 100%;
                margin-bottom: 20px;
                border: 0;
                padding: 10px;
                border-bottom: 1px solid rgb(128, 125, 125);
                font-size: 15px;
                outline: none;
            }


            .login {
                text-align: center;
                padding: 10px;
                width: 100%;
                margin-top: 40px;
                background-color: cornflowerblue;
                color: white;
            }

            .msg {
                text-align: center;
                line-height: 88px;
            }

            a {
                text-decoration-line: none;
                color: cornflowerblue;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="big">
                <div class="header">注册</div>
                <form id="form" class="form-wrapper" method="post" action="/register">
                    <input type="text" id="username" name="username" placeholder="请输入用户名" class="input-item">
                    <input type="password" id="password" name="firstPassword" placeholder="请输入8至16位密码" maxlength="16" class="input-item">
                    <input type="password" id="password2" name="secondPassword" placeholder="请再次输入密码" class="input-item">
                    <input type="email" id="email" name="email" placeholder="请输入邮箱（选填）" class="input-item">
<%--                    <input type="submit" class="login" value="点击注册" onclick="regist()">--%>
                </form>
                <button class="login" onclick="regist()">注册 </button>
                <div class="msg">
                    已经有账户了？
                    <a href="Login.jsp">立即登录</a>
                </div>
            </div>
        </div>
    <div style="display: none" id="u"><%=request.getAttribute("cannot")%></div>
    </body>
</html>
<script>
    window.onload = function () {
        var u=document.getElementById('u').innerText;
        console.log(u);
        if (u=='账号已存在') {
            alert("账号已存在")
        }
    }
    regist = function () {
        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;
        var password2 = document.getElementById('password2').value;
        var email = document.getElementById('email').value;
        var num = /^\w+@[a-z0-9]+\.[a-z]+$/i;
        if (username.length == 0) {
            alert('用户名不能为空')
        }
        else {
            if (password.length < 8) {
                alert('密码长度过短')
            }
            else {
                if (password != password2) {
                    alert('前后密码不一致')
                }
                else {
                    if (email.length!=0&num.test(email) == false) {//邮箱爱写不写
                        alert('电子邮箱格式错误')
                    }
                    else {
                        var form = document.getElementById('form');
                        form.submit();
                    }
                }
            }
        }
    }
</script>
